<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>主页</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <!--使用Bootstrap的js插件，必须先调入jQuery-->
    <script src="http://libs.baidu.com/jquery/1.9.0/jquery.min.js"></script>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.5.0/dist/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
    <link rel="stylesheet" media="screen and (max-width: 300px)" href="../static/css/mainPagePc.css">
    <script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.5.0/dist/js/bootstrap.min.js" integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI" crossorigin="anonymous"></script>
    <!--引入vue-->
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <!--引入axios-->
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>

    <style>
        body .pointer{
            cursor: pointer;
        }
        body .pointer:hover{
            color: #007bff;
        }
        body .cha{
            cursor: pointer;
            text-align: right;
        }
        body #info .cha:hover{
            animation:rotate 1s infinite;!important;
            color: #007bff;!important;
        }
        @keyframes rotate {
            0%{-webkit-transform: rotate(0deg);}
            100%{-webkit-transform: rotate(180deg);}
        }
        .rele{
            position: relative;
        }
        .fenye{
            /*text-align: center;*/
            /*position: absolute;*/
            /*bottom: 1px;*/
            /*left: 50%;*/
            /*transform: translate(-50%,0);*/
        }
        body{
            background: rgb(250,250,250);
        }
        #info{
            background:white;
            position: relative;
        }
        h2,#infoArea{
            margin-top: 20px;
            margin-bottom: 20px;
            /*box-shadow: 2px 2px 2px 1px rgba(0, 0, 0, 0.2),-2px -2px 2px 1px rgba(0, 0, 0, 0.2);*/
        }
    </style>
</head>
<body class="">
    <div class="bg-light" id="app" v-if="showPage">


        <!-- Modal -->
        <div class="modal fade" id="changePwd" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
            <div class="modal-dialog modal-dialog-centered" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title" id="exampleModalCenterTitle">修改密码</h5>
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                        </button>
                    </div>
                    <div class="modal-body">
                        <input type="text" class="form-control" id="change" placeholder="new password">
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-outline-secondary" data-dismiss="modal">取消</button>
                        <button type="button" @click="changePwd()" class="btn btn-outline-primary">确认修改</button>
                    </div>
                </div>
            </div>
        </div>
        <div class="container bg-light">
            <nav class="navbar navbar-expand-lg sticky-top navbar-light bg-light">
                <a class="navbar-brand" href="./index.html">
                    <img src="/static/img/sut.jpg" style="width: 32px;height: 32px;" alt="">
                    Spoc
                </a>
                <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarTogglerDemo02" aria-controls="navbarTogglerDemo02" aria-expanded="false" aria-label="Toggle navigation">
                    <span class="navbar-toggler-icon"></span>
                </button>
                <div class="collapse navbar-collapse" id="navbarTogglerDemo02">
                    <ul class="navbar-nav mr-auto mt-2 mt-lg-0">
                        <li class="nav-item active">
                            <div class="dropdown">
                                <button class="btn btn-light dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                                    {{ name }}
                                </button>
                                <div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
                                    <!-- Button trigger modal -->
                                    <button  class="dropdown-item" data-toggle="modal" data-target="#changePwd">
                                        修改密码
                                    </button>
                                    <a class="dropdown-item" @click="logout()" href="javascript:void(0)">退出登录</a>
                                </div>
                            </div>
                        </li>
                        <li class="nav-item active">
                            <a class="nav-link" href="/course/mainPage">课程 <span class="sr-only">(current)</span></a>
                        </li>
                        <li v-if="authority == 'student'" class="nav-item">
                            <a class="nav-link" href="http://127.0.0.1/course/my_collections">试题册</a>
                        </li>

                    </ul>
                    <form class="form-inline my-2 my-lg-0">
                        <input class="form-control mr-sm-2" type="search" placeholder="Search">
                        <button class="btn btn-outline-success my-2 my-sm-0" type="submit">搜索</button>
                    </form>
                </div>
            </nav>
        </div>
        <div class="container" id="infoArea" >
            <!-- 课程导航栏 只有手机端显示 -->
            <div>
                <ul class="nav nav-tabs d-md-none">
                  <li class="nav-item" v-for="(items, indexs) in courseList" @click="changeCourse(indexs)" >
                    <a class="nav-link" v-bind:class="{active:indexs==current}" href="#">{{ items.name }}</a>
                  </li>
                </ul>
            </div>
            <div class="row" style="height: 620px;">
                <!--左侧边栏 手机端隐藏-->
                <div class="col-3 shadow-sm d-none d-md-flex">
                    <div class="card" style="min-width: 253px">
                        <img style="min-height: 250px;" class="card-img-top" :src="current==0?'../static/img/java.jpg':'../static/img/cg.jpg'" alt="课程">
                        <div class="card-body">
                            <h5 class="card-title">{{ name }}</h5>
                            <p class="card-text" style="margin-bottom: 10px">good good study,day day up</p>
                        </div>
                        <div class="list-group list-group-flush">
                            <button v-for="(item, index) in courseList" @click="changeCourse(index)" v-bind:class="{active:index==current}" type="button" class="list-group-item list-group-item-action">{{ item.name }}</button>
                        </div>
                        <div class="list-group list-group-flush">
                            <button class="list-group-item list-group-item-action disabled">关于我们</button>
                            <button class="list-group-item list-group-item-action disabled">提交建议</button>
                        </div>

                    </div>
                </div>
                <!--主要内容区,显示课程信息以及所有试卷概览-->
                <div id="info" class="col shadow">
                    <div>
                        <h2 class="d-none d-md-flex">{{ courseList[current].name }}</h2>
                    </div>
                    <div>
                        <!-- 所有试卷、试题导航栏 -->
                        <ul class="nav nav-tabs" id="infoTab" role="tablist">
                          <li class="nav-item">
                            <a class="nav-link active" id="paperTab" data-toggle="tab" href="#paper" role="tab" aria-controls="paper" aria-selected="true">所有试卷</a>
                          </li>
                          <li class="nav-item">
                            <a class="nav-link" id="profile-tab" data-toggle="tab" href="#questions" role="tab" aria-controls="questions" aria-selected="false">所有试题</a>
                          </li>
                        </ul>
                        <div class="tab-content" id="myTabContent">
                          <div class="tab-pane fade show active" id="paper" role="tabpanel" aria-labelledby="paper-tab">
                            <div class="list-group" style="overflow:hidden;white-space:nowrap;text-overflow:ellipsis;">

                                <div  v-for="(paper,index) in paperList" class="list-group-item list-group-item-action rele">
                                    <div class="row">
                                        <div class="col-8 col-md-9" style="overflow:hidden;white-space:nowrap;text-overflow:ellipsis;">
                                            <span class="pointer" @click="gotoDoPaper(paper)">{{ paper.paperName }}</span>
                                        </div>
                                        <div class="col-2 col-md-2" style="overflow:hidden;white-space:nowrap;text-overflow:ellipsis;">
                                            <span class="pointer" @click="gotoDoPaper(paper)">已作答{{ paper.doneTimes }}人次</span>
                                        </div>
                                        <div class="col-2 col-md-1">
                                            <a class="cha" @click="deletePaper(paper)" v-if="authority!='student'">×</a>
                                        </div>
                                    </div>
                                </div>

                                <!--分页按钮-->
                                <div class="sticky-bottom row fenye justify-content-center" style="margin-top: 10px">
                                    <nav aria-label="Page navigation example">
                                        <ul class="pagination">
                                            <!--向前页标志-->
                                            <li class="page-item" :class="{'disabled':currentPaper<=1}">
                                                <a  @click="paperList=pageData(coursePaper,currentPaper-1, 'paper')" class="page-link" href="javascript:void(0) " aria-label="Previous">
                                                    <span aria-hidden="true">&laquo;</span>
                                                    <span class="sr-only">Previous</span>
                                                </a>
                                            </li>
                                            <!--页数-->
                                            <li  class="page-item disabled"><a class="page-link" href="#">第{{ currentPaper }}页 共{{ totalPaper }}页</a></li>
                                            <!--向后页标志-->
                                            <li class="page-item" :class="{'disabled':currentPaper>=totalPaper}">
                                                <a  @click="paperList=pageData(coursePaper,currentPaper+1, 'paper')" class="page-link" href="javascript:void(0) " aria-label="Next">
                                                    <span aria-hidden="true">&raquo;</span>
                                                    <span class="sr-only">Next</span>
                                                </a>
                                            </li>
                                        </ul>
                                    </nav>
                                </div>
                            </div>
                          </div>
                          <div class="tab-pane fade" id="questions" role="tabpanel" aria-labelledby="questions-tab">
                            <div class="list-group">
                                <div class="list-group-item list-group-item-action rele">

                                    <div v-if="authority != 'student'" class="btn-group" role="group" aria-label="Basic">
                                        <button type="button" @click="gotoAdd()" class="btn btn-secondary">添加试题</button>
                                        <button type="button" @click="createPaper()" class="btn btn-secondary" data-toggle="modal" data-target="#exampleModalLong">生成试卷</button>
                                    </div>

                                </div>



                                <!-- Modal -->
                                <!--<div class="modal fade" id="exampleModalCenter" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">-->
                                    <!--<div class="modal-dialog modal-dialog-centered" role="document">-->
                                        <!--<div class="modal-content">-->
                                            <!--<div class="modal-header">-->
                                                <!--<h5 class="modal-title" id="exampleModalCenterTitle">生成试卷</h5>-->
                                                <!--<button type="button" class="close" data-dismiss="modal" aria-label="Close">-->
                                                    <!--<span aria-hidden="true">&times;</span>-->
                                                <!--</button>-->
                                            <!--</div>-->
                                            <!--<div class="modal-body" style="overflow:hidden;white-space:nowrap;text-overflow:ellipsis;">-->
                                                <!--<div class="form-group">-->
                                                    <!--<label for="input1">试卷名</label>-->
                                                    <!--<input type="text" class="form-control" id="input1" placeholder="试卷名">-->
                                                <!--</div>-->
                                                <!--<div>-->
                                                    <!--共选中:{{ selected.length }}道题-->
                                                <!--</div>-->
                                                <!--<div v-for="question in selected" >-->
                                                    <!--{{ question.describe }}-->
                                                <!--</div>-->
                                            <!--</div>-->
                                            <!--<div class="modal-footer">-->
                                                <!--<button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>-->
                                                <!--<button type="button" class="btn btn-primary" @click="submit()">确认生成！</button>-->
                                            <!--</div>-->
                                        <!--</div>-->
                                    <!--</div>-->
                                <!--</div>-->

                                <!-- Modal -->
                                <div class="modal fade" id="exampleModalLong" tabindex="-1" role="dialog" aria-labelledby="exampleModalLongTitle" aria-hidden="true">
                                    <div class="modal-dialog" role="document">
                                        <div class="modal-content">
                                            <div class="modal-header">
                                                <h5 class="modal-title" id="exampleModalLongTitle">生成试卷</h5>
                                                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                                    <span aria-hidden="true">&times;</span>
                                                </button>
                                            </div>
                                            <div class="modal-body"  style="overflow:hidden;white-space:nowrap;text-overflow:ellipsis;">
                                                <div class="form-group">
                                                    <label for="input1">试卷名</label>
                                                    <input type="text" class="form-control" id="input1" placeholder="试卷名">
                                                </div>
                                                <div>
                                                    共选中:{{ selected.length }}道题
                                                </div>
                                                <div v-for="question in selected" >
                                                    {{ question.describe }}
                                                </div>
                                            </div>
                                            <div class="modal-footer">
                                                <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
                                                <button type="button" class="btn btn-primary" @click="submit()">确认生成！</button>
                                            </div>
                                        </div>
                                    </div>
                                </div>



                                <div  v-for="(question,ind) in questionsList" class="list-group-item list-group-item-action rele">
                                    <!--<input style="margin-left: 10px;position: static!important;" :id="'x'+(ind+(currentQuestion-1)*8)" type="checkbox" class="form-check-input" name="Check1">-->
                                    <div class="row " style="overflow:hidden;white-space:nowrap;text-overflow:ellipsis;">
                                        <div class="col-5 col-md-6 form-check" style="overflow:hidden;white-space:nowrap;text-overflow:ellipsis;">
                                            <input v-if="authority!='student'" class="form-check-input" type="checkbox" value="" name="Check1" :id="'x'+(ind+(currentQuestion-1)*8)">
                                            <label class="form-check-label" :for="'x'+(ind+(currentQuestion-1)*8)">
                                                {{ ind+(currentQuestion-1)*8 + 1 }}.
                                            </label>
                                            <span @click="gotoQuestion(question.tqNo)" class="pointer">{{ question.describe }}</span>
                                        </div>
                                        <div class="col-2 col-md-2" style="overflow:hidden;white-space:nowrap;text-overflow:ellipsis;">
                                            <span>{{ question.type=='ShortAnswerQuestion'?'简答题':question.type=='SingleSelection'?'单选题':'多选题' }}</span>
                                        </div>
                                        <div class="col-2 col-md-2" style="overflow:hidden;white-space:nowrap;text-overflow:ellipsis;">
                                            <span>错误率：{{ Math.round(question.rate) }}%</span>
                                        </div>
                                        <div class="col-1 col-md-1" >
                                            <!-- Button trigger modal -->
                                            <button @click="getComments(question)" type="button" class="btn btn-link btn-sm" data-toggle="modal" data-target="#Long">
                                                讨论区
                                            </button>
                                        </div>
                                        <div class="col-2 col-md-1"><a class="cha" @click="deleteQuestion(question)" v-if="authority!='student'">×</a></div>
                                    </div>
                                </div>

                                <!--讨论区-->
                                <div class="modal fade" id="Long" tabindex="-1" role="dialog" aria-labelledby="exampleModalLongTitle" aria-hidden="true">
                                    <div class="modal-dialog" role="document">
                                        <div class="modal-content">
                                            <div class="modal-header">
                                                <h5 class="modal-title" id="LongTitle">{{ question.describe }}的讨论区</h5>
                                                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                                    <span aria-hidden="true">&times;</span>
                                                </button>
                                            </div>
                                            <div class="modal-body" >
                                               <div class="card bg-light" v-for="comments in commentList" style="margin-bottom: 10px">
                                                   <div v-if="commentList.length"  class="card-body">
                                                       <h5 class="card-title">{{ comments.stuName }}:</h5>
                                                       <p class="card-text">{{ comments.comment }}</p>
                                                       <p class="card-text"><small class="text-muted">{{comments.time}}</small></p>
                                                   </div>
                                               </div>
                                                <div class="card bg-light">
                                                    <div v-if="commentList.length==0"  class="card-body">
                                                        <h5 class="card-title">这道题还没有人讨论呢</h5>
                                                    </div>
                                                </div>
                                               <div class="alert alert-warning alert-dismissible fade show" id="alert" role="alert">
                                                   <strong>提示：</strong> 评论一经发表无法撤回！！！
                                                   <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                                                       <span aria-hidden="true">&times;</span>
                                                   </button>
                                               </div>
                                            </div>
                                            <div class="modal-footer">
                                                <div class="input-group mb-3">
                                                    <input type="text" id="comment" class="form-control" placeholder="畅所欲言吧，少年！" aria-label="畅所欲言吧，少年！" aria-describedby="basic-addon2">
                                                    <div class="input-group-append">
                                                        <button @click="sendComments(question)" type="button" class="btn btn-outline-secondary">发表评论</button>
                                                    </div>
                                                </div>

                                            </div>
                                        </div>
                                    </div>
                                </div>

                                <!--分页按钮-->
                                <div class="sticky-bottom row container justify-content-center" style="margin-top: 10px">
                                    <nav aria-label="Page navigation example">
                                        <ul class="pagination">
                                            <!--向前页标志-->
                                            <li class="page-item" :class="{'disabled':currentQuestion<=1}">
                                                <a  @click="questionsList=pageData(courseQuestions,currentQuestion-1, 'question');saveSelected()" class="page-link" href="javascript:void(0) " aria-label="Previous">
                                                    <span aria-hidden="true">&laquo;</span>
                                                    <span class="sr-only">Previous</span>
                                                </a>
                                            </li>
                                            <!--页数-->
                                            <li  class="page-item  disabled"><a class="page-link" href="#">第{{ currentQuestion }}页 共{{ totalQuestions }}页</a></li>
                                            <!--向后页标志-->
                                            <li class="page-item" :class="{'disabled':currentQuestion>=totalQuestions}">
                                                <a  @click="questionsList=pageData(courseQuestions,currentQuestion+1,'question');saveSelected()" class="page-link" href="javascript:void(0) " aria-label="Next">
                                                    <span aria-hidden="true">&raquo;</span>
                                                    <span class="sr-only">Next</span>
                                                </a>
                                            </li>
                                        </ul>
                                    </nav>
                                </div>
                            </div>
                          </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

<script>
    $(function () {
        $('[data-toggle="popover"]').popover();
    });
    var app = new Vue({
        el: "#app",
        data:{
            // 课程列表
            courseList:[],
            // 该课程所有试卷
            coursePaper:[],
            // 当前分页显示的试卷
            paperList:[],
            // 该课程所有试题
            courseQuestions:[],
            // 当前分页显示的试题
            questionsList:[],
            // 当前选中试卷的分页 默认第一页
            currentPaper:1,
            // 当前选中试题的分页 默认第一页
            currentQuestion:1,
            // 试卷总共页
            totalPaper:0,
            // 试题总共多少页
            totalQuestions:0,
            // 当前选中的课程index
            current:0,
            // 用户名
            name:'',
            // userId
            userId:'',
            // 用户权限
            authority:'',
            // 是否显示页面，在页面数据请求完之前为false
            showPage:false,
            // 选中的试题
            selected:[],
            // 获取到的评论
            commentList:[],
            question:{}
        },
        mounted:function(){
            this.getAuothority();
            this.getCourse();
        },
        methods:{
            // 退出登录
            logout:function(){
                axios.get('http://127.0.0.1/logout');
                $(location).attr('href', 'http://127.0.0.1');
            },
            // 获取用户权限和姓名 保存再authority和name
            getAuothority:function(){
                this.name = localStorage.name;
                this.authority = localStorage.authority;
                this.userId = localStorage.id;
                console.log('用户：'+ this.name + '\n'+ '权限：' + this.authority);
            },
            // 获取所有课程
            getCourse:function(){
                var that = this;
                axios.get('http://127.0.0.1/course').then(function(response){
                    that.courseList = response.data.courses;
                    console.log(response);
                    console.log('成功获取课程');
                    that.getPaper();
                    that.getQuestions();
                }).catch(function(err){
                    console.log(err);
                    alert('无法加载课程，请检查你的网络！');
                });
            },
            // 获取课程对应的试卷
            getPaper:function(){
                var that = this;
                console.log("课程号"+that.courseList[that.current].cno);
                axios.get('http://127.0.0.1/course/allTestPapers/' + that.courseList[that.current].cno).then(function(response){
                    that.coursePaper = response.data.testPapers;
                    console.log(response);
                    console.log('成功获取试卷');
                }).catch(function(err){
                    console.log(err);
                    alert('无法加载试卷，请检查你的网络！');
                })
            },
            // 获取课程对应的试题
            getQuestions:function(){
                var that = this;
                axios.get('http://127.0.0.1/course/allTestQuestions/' + that.courseList[that.current].cno).then(function(response){
                    that.courseQuestions = response.data.testQuestions;
                    console.log(response);
                    console.log('成功获取试题');
                    that.totalPaper = that.setPage(that.coursePaper);
                    console.log('试卷共'+that.totalPaper);
                    that.totalQuestions = that.setPage(that.courseQuestions);
                    console.log('试题共'+that.totalQuestions);
                    that.paperList = that.pageData(that.coursePaper,1,'paper');
                    that.questionsList = that.pageData(that.courseQuestions,1,'question');
                }).catch(function(err){
                    console.log(err);
                    alert('无法加载试题，请检查你的网络！');
                })
            },
            // 改变当前的课程 并重新获取试卷和试题
            changeCourse:function (index) {
                this.current = index;
                this.getPaper();
                this.getQuestions();
            },
            deletePaper:function(paper) {
                var that = this;
                axios.get('http://127.0.0.1/teacher/course/deleteTestPaper/' + paper.tpNo).then(function(response){
                    console.log(response);
                    that.getPaper();
                    that.getQuestions();
                });
            },
            deleteQuestion:function(question){
                var that = this;
                axios.get('http://127.0.0.1/teacher/course/deleteQuestion/' + question.tqNo).then(function(response){
                    console.log(response);
                    that.getPaper();
                    that.getQuestions();
                });
            },
            setPage:function(courseQuestions){
                console.log(Math.ceil(courseQuestions.length / 8) || 1);
                return Math.ceil(courseQuestions.length / 8) || 1;
            },
            pageData:function (data,pageIndex,type) {


                if(type == 'paper'){
                    this.currentPaper = pageIndex;
                    console.log('试卷第'+pageIndex)
                }else{
                    this.currentQuestion = pageIndex;
                    console.log('试题第'+pageIndex)
                }
                var begin = (pageIndex - 1)*8;
                var end = pageIndex*8;
                this.showPage = true;
                return data.slice(
                    begin,
                    end
                );
            },
            gotoQuestion:function (tqNo) {
                localStorage.setItem('tqNo',tqNo);
                if (this.authority == 'teacher'){
                    $(location).attr('href', 'http://127.0.0.1/teacher/course/mod_question');
                } else{
                    $(location).attr('href', 'http://127.0.0.1/course/stuquestion');
                }


            },
            gotoAdd:function () {
                localStorage.setItem('cno',this.courseList[this.current].cno);
                $(location).attr('href', '/teacher/course/add_question');
            },
            gotoDoPaper:function(paper){
                localStorage.setItem('cno',this.courseList[this.current].cno);
                localStorage.setItem('tpNo',paper.tpNo);
                localStorage.setItem('paperName',paper.paperName);
                $(location).attr('href', '/course/do_paperPage');
            },
            createPaper:function () {
                var that = this;
                $("input:checkbox[name=Check1]:checked").each(function(index, element){
                    var sel = parseInt(element.id.substr(1));
                    that.selected.push(that.courseQuestions[sel]);
                });
            },
            submit:function () {
                var name = $('#input1').val();
                var that = this;
                var TqNos = [];
                function Tq(a) {
                    this.TqNo = a;
                }
                for (let i = 0; i<that.selected.length;i++){
                    TqNos.push(new Tq(that.selected[i].tqNo.toString()));
                }

                var data = {
                    "Cno":that.courseList[that.current].cno,
                    "paperName":name,
                    "TqNos":TqNos
                };
                console.log('生成试卷的卷名：'+name);
                console.log('生成试卷的课程号'+ that.courseList[that.current].cno);
                console.log('生成试卷的题号'+TqNos + ' '+ TqNos[0]);
                axios.post("http://127.0.0.1/teacher/course/addTestPaper", data).then(res => {
                    console.log(res);
                alert("成功!");
                window.location.reload();
                }).catch(err => {
                    console.error(err);
                    alert("失败!");
                })
            },
            saveSelected:function () {
                var that = this;
                $("input:checkbox[name=Check1]:checked").each(function(index, element){
                    var sel = parseInt(element.id.substr(1));
                    that.selected.push(that.courseQuestions[sel]);
                    $(this).prop('checked',false);

                });
            },
            // 获取评论
            getComments:function (question) {
                this.question = question;
                var that = this;
                axios.get('http://127.0.0.1/course/testQuestion/getComments/?TqNo=' + question.tqNo).then(function(response){
                    console.log('成功获取评论');
                    console.log(response);
                    that.commentList = response.data.commentList;
                    that.commentTqNo = question.tqNo;

                });
            },
            //  发表评论
            sendComments:function (question) {
                var that = this;
                var co = $('#comment').val().trim().replace(/\s/g,"");
                console.log('tqNo:'+question.tqNo);
                console.log('co:'+co);
                console.log('userId:'+that.userId);
                axios.get('http://127.0.0.1/course/testQuestion/addComment?TqNo=' + question.tqNo + '&comment=' + co +
                '&userId=' + that.userId).then(function(response){
                    console.log('成功发表评论');
                    console.log(response);
                    $("#alert").alert();
                    that.getComments(question);
                });
            },
            changePwd:function () {
                var pwd = $('#change').val().trim().replace(/\s/g,"");
                if(pwd ==''){
                    alert('不能为空！');
                }else{
                    axios.get('http://127.0.0.1/course/changePassword/?password=' + pwd).then(function(response){
                        alert('成功修改密码');
                        console.log(response);
                    });
                }
            }
        }
    })
</script>
</body>
</html>